package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.query.ChartclaimQueryObject;
import cn.wolfcode.crm.query.ChartsalesQueryObject;
import cn.wolfcode.crm.service.IChartService;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@Controller
@RequestMapping("chart")
public class ChartController {

    @Autowired(required = false)
    private IChartService chartService;

    @RequestMapping("saleview")
    @RequiresPermissions(value = {"chart:view","字典页面"},logical = Logical.OR)
    public String view() throws Exception{
        return "chart/sales";
    }

    @RequestMapping("sales/list")
    @ResponseBody
    public PageResult list(ChartsalesQueryObject qo) throws Exception{
        PageResult query = chartService.query(qo);

        return query;
    }

    @RequestMapping("salegroupby")
    @ResponseBody
    public Object selectgroupby(){
        Map<Integer, Object> map = ChartsalesQueryObject.map;
        List<Map<String ,Object>> list=new ArrayList<>();
        Set<Map.Entry<Integer, Object>> entries = map.entrySet();
        for (Map.Entry<Integer,Object> entry : entries) {
            HashMap<String, Object> hasMap = new HashMap<>();
            Integer key = entry.getKey();
            hasMap.put("key",key);
            Object value = entry.getValue();
            hasMap.put("value",value);
            list.add(hasMap);
        }
        return list;
    }

   /*理赔报表*/
    @RequestMapping("sclaimview")
    @RequiresPermissions(value = {"chart:view","字典页面"},logical = Logical.OR)
    public String sclaimview() throws Exception{
        return "chart/sclaim";
    }

    @RequestMapping("sclaim/list")
    @ResponseBody
    public PageResult list(ChartclaimQueryObject qo) throws Exception{
        PageResult query = chartService.queryclaim(qo);

        return query;
    }

    @RequestMapping("sclaimgroupby")
    @ResponseBody
    public Object selectsclaimgroupby(){
        Map<Integer, Object> map = ChartclaimQueryObject.map;
        List<Map<String ,Object>> list=new ArrayList<>();
        Set<Map.Entry<Integer, Object>> entries = map.entrySet();
        for (Map.Entry<Integer,Object> entry : entries) {
            HashMap<String, Object> hasMap = new HashMap<>();
            Integer key = entry.getKey();
            hasMap.put("key",key);
            Object value = entry.getValue();
            hasMap.put("value",value);
            list.add(hasMap);
        }
        return list;
    }
    /*理赔报表*/















}
